package com.lee.study.shouji.engine;

import java.io.IOException;
import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

import com.lee.study.shouji.domain.UpdateInfo;

public class UpdateInfoParser {
	
	public static UpdateInfo getUpdateInfo(InputStream is) throws XmlPullParserException, IOException{
		//得到解析器
		XmlPullParser pullParser = Xml.newPullParser();
		//设置解析器
		pullParser.setInput(is,"utf-8");
		//定位到文档开头
		int type = pullParser.getEventType();
		UpdateInfo updateInfo = new UpdateInfo();
		//只要不到文档的某位就一直循环
		while(type != XmlPullParser.END_DOCUMENT){
			
			switch (type) {
			case XmlPullParser.START_TAG:
				if("version".equals(pullParser.getName())){
					String version = pullParser.nextText();
					updateInfo.setVersion(version);
				}else if("description".equals(pullParser.getName())){
					String description = pullParser.nextText();
					updateInfo.setDescription(description);
				}else if("apkurl".equals(pullParser.getName())){
					String apkurl = pullParser.nextText();
					updateInfo.setApkurl(apkurl);
				}
				break;

			default:
				break;
			}
			
			type = pullParser.next();
		}
		
		return updateInfo;
	}

}
